package pack2;

import java.io.*;
import java.net.InetAddress;
import java.net.Socket;

/**
 * @author wenze-zero
 */
public class Client {
    public static void main(String[] args) throws IOException {
        Socket sk=new Socket(InetAddress.getByName("172.22.17.255"),10000);
        OutputStream os=sk.getOutputStream();
        BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
        ClientThread CT=new ClientThread(sk);
        Thread t1=new Thread(CT);
        String sline;
        t1.start();
        while (true){
            sline=br.readLine();
            os.write(sline.getBytes());
            System.out.println("客户端"+sline);
        }
    }
}
class ClientThread implements Runnable {
    private Socket sk;
    public ClientThread(){
    }
    public ClientThread(Socket sk){
        this.sk=sk;
    }
    @Override
    public void run() {
        try {
            byte[] bys=new byte[1024];
            int len;
            String aline;
            while (true){
                InputStream is=sk.getInputStream();
                len=is.read(bys);
                aline=new String(bys,0,len);
                System.out.println("服务器:"+aline);
            }
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}
